<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String type = request.getParameter("type") == null ? "one" : request.getParameter("type");
	String pagination = request.getParameter("page") == null ? "false" : request.getParameter("page");
	String url = request.getParameter("url");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择人员</title>
	<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="../css/pop-page.css" />
	<script type="text/javascript" src="../easyui/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../js/win.js"></script>
	<script type="text/javascript">
		var type = '<%=type%>';
		function searchUser(value){
			if($.trim(value) != ""){
				$("#dg").datagrid({
					url:"../user/searchUser.do",
					queryParams:{"user.name":value}
				});
			}
		}
		
		function selectUser(){
			var rows = $("#dg").datagrid('getSelections');
			if(type == "one"){//选择一个
				if (rows.length != 1){
					$.messager.alert("提示", "&nbsp;&nbsp;<br/>请选择一条记录!", "info");
				} else {
					parent.selectUser( rows[0].id, rows[0].name );
				}
			} else {//选择多个
				if (rows.length != 0){
					$.messager.alert("提示", "&nbsp;&nbsp;<br/>请选择一条记录!", "info");
				} else {
					var ids = "";
					var names = "";
			        var arrId = [];
			        var nameArr = [];
			        for (i=0;i<rows.length;i++){
			            arrId.push(rows[i].id);
			            nameArr.push(rows[i].name);
			        }
			        ids = arrId.join(",");
			        names = nameArr.join(",");
					parent.selectUser(ids, names);
				}
			}
		}
	</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'center',border:false">
		<div class="dg-content">
			<table id="dg" class="easyui-datagrid"
				data-options="rownumbers:true,toolbar:'#searchDiv',
					fitColumns:true,iconCls:'icon-users'">
				<thead>
					<tr>
						<th data-options="field:'ck',checkbox:true"></th>
						<th data-options="field:'id',hidden:true"></th>
						<th data-options="field:'name',width:100,align:'center'">姓名</th>
						<th data-options="field:'username',width:100,align:'center'">用户名</th>
					</tr>
				</thead>
			</table>
			<div id="searchDiv" style="padding: 5px;">
				<input class="easyui-searchbox"
					data-options="prompt:'请输入姓名',searcher:searchUser" />
			</div>
		</div>
	</div>
	<div data-options="region:'south'" class='fm-btn'>
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="selectUser()">确定</a>
	</div>
</body>
</html>